package com.hsxc.cdz.mgmt.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hsxc.cdz.base.bean.MyUser;
import com.hsxc.cdz.base.dao.MyUserDao;

@Component
public class MyUserManager implements MyUserManagerIntf {

	//app用户类型为0
	private int USERTYPE =0 ;
	
	@Autowired //自动注入类
    private MyUserDao userDao;
	
	/**
	 * 用户登录
	 * @param password 用户的密码
	 * @param username 用户注册名
	 * @return 用户的全部信息,为null时，未找到该用户
	 */
	public MyUser userLogin (String password,String username){
		MyUser myUser = new MyUser();
		myUser.setRegName(username);
		myUser.setPassword(password);
		return userDao.selectUser(myUser);
	}
	
	/**
	 * 插入用户
	 * @param user 用户信息
	 * @return 0：插入失败 ，1：插入成功
	 */
	public int insertOne(MyUser user){
		return userDao.insertUser(user);
	}
	
	public int updateUser(MyUser user) {
		return userDao.updateUser(user);
	}
	public int updateUserByTel(MyUser user){
		return userDao.updateUserByTel(user);
	}
	
	public int deleteOne(String regName){
		MyUser user = new MyUser();
		user.setRegName(regName);
		return userDao.deleteUser(user);
	}
	/**
	 * 根据手机号码查找用户
	 * @param tel
	 * @return MyUser
	 */
	public MyUser loadMyUserByMobile(String tel){
		System.out.println("传递的电话号码为"+tel);
		MyUser myUser = new MyUser();
		myUser.setTel(tel);
		return userDao.selectUser(myUser);
		
	}

	@Override
	public int updatePointminus(String tel) {
		MyUser myUser = new MyUser();
		myUser.setTel(tel);
		return userDao.updatePointminus(myUser);
	}

	public int getUSERTYPE() {
		return USERTYPE;
	}

	public void setUSERTYPE(int uSERTYPE) {
		this.USERTYPE = uSERTYPE;
	}

	
}
